<div id="content-flash">
    <?php if($this->session->flashdata('article') != null){ ?>
    <p id="content-notif">
        <?php
        echo $this->session->flashdata('article');
        ?>
    </p>
    <?php } ?>
</div>
<div id="content-title">
    <p id="ctitle-p">
        Edit Article
    </p>
</div>
<div class="hor-line"></div>
<div id="content">
    <form action="<?php echo base_url() ?>article/edit" method="post" enctype="multipart/form-data">
        <div class="content-field">
            <p class="p-wrapper">
                <span class="field label">
                    <label>TITLE</label>
                    <input type="text" name="ftitle" id="ftitle" value="<?php echo $article->title; ?>"/>
                </span>
            </p>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>CATEGORY</label>
                    <select name="fcategory">
                        <?php foreach ($category->result() as $row) { ?>
                            <option value="<?php echo $row->category_id; ?>" <?php echo ($row->category_id == $article->category_id) ? 'selected="selected"' : ''; ?>>
                                <?php echo $row->category_name; ?>
                            </option>
                        <?php } ?>
                    </select>
                </span>
            </p>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span class="field label">
                    <label>PUBLISHED</label>
                    <select name="fpublished">
                        <option value="1" <?php echo ($article->published == 1) ? 'selected="selected"' : ''; ?>>Yes</option>
                        <option value="0" <?php echo ($article->published == 0) ? 'selected="selected"' : ''; ?>>No</option>
                    </select>
                </span>
            </p>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>CONTENT</label>
                </span>
            </p>
        </div>
        <div class="field-separator"></div>
        <div class="content-field">
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#fcontent").cleditor({
                        width:870
                    });
                });
            </script>
            <textarea id="fcontent" style="width:100%" name="fcontent"><?php echo $article->content; ?></textarea>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>CURRENT IMAGE</label>
                </span>
            </p>
        </div>
        <div class="field-separator"></div>
        <div class="content-field">
            <table id="table-image">
                <tr class="tr-title">
                    <td class="td-no">
                        No
                    </td>
                    <td class="td-image">
                        Image
                    </td>
                    <td class="td-title">
                        Title
                    </td>
                    <td class="td-filename">
                        Filename
                    </td>
                    <td class="td-action">
                        Action
                    </td>
                </tr>
                <?php
                    $count = 1;
                    foreach ($image->result() as $row) {
                        $width = $row->image_width;
                        $height = $row->image_height;
                ?>
                <tr <?php echo (($count % 2) == 0) ? 'class="tr-round"' : ''; ?>>
                    <td class="td-no"><?php echo $count; ?>.</td>
                    <td class="td-image">
                        <img 
                            src="<?php echo base_url().'img/uploads/thumb/'.$row->image_url;?>"
                            style="<?php echo ($height >= $width) ? 'height:100px' : 'width:150px'?>"
                         />
                    </td>
                    <td class="td-title"><?php echo $row->image_title; ?></td>
                    <td class="td-filename"><?php echo $row->image_url; ?></td>
                    <td class="td-action">
                        <a href="<?php echo base_url() . 'cp/edit_image/' . $row->image_id; ?>">
                            Edit
                        </a>
                        <a href="<?php echo base_url() . 'article/delete_image/' . $row->image_id; ?>">
                            Delete
                        </a>
                    </td>
                </tr>
                <?php
                    $count++;
                    }
                ?>
            </table>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>IMAGE UPLOAD</label>
                </span>
            </p>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>IMAGE TITLE</label>
                    <input type="text" name="fimage-title" />
                </span>
            </p>
        </div>
        <div class="content-field">
            <p class="p-wrapper">
                <span  class="field label">
                    <label>IMAGE FILE</label>
                    <input type="file" name="fimage-file" id="fmedia-file"/>
                </span>
            </p>
        </div>
        <div class="field-separator"></div>
        <div class="field-separator"></div>
        <div class="content-field">
            <input type="image" src="<?php echo base_url(); ?>img/style/submit_button.png"/>
        </div>
    </form>
</div>